package winTime.process.source;
import java.io.BufferedReader;
import java.io.FileReader;

import winTime.Start;
import winTime.vo.tickData;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * @author fatsung
 * 讀取檔案資料進來,將資料拆解,存入queue之中
 */
public class ipushFileHandler extends Thread{
	private static final Logger log=LoggerFactory.getLogger(ipushFileHandler.class);
	@Override
	public void run(){
		log.trace("程式啟動");
		String str="";
		BufferedReader br=null;
		int cnt=0;
		try{
			br = new BufferedReader(new FileReader("C:/java/data/getIpushFutureData"+Start.dateTag+".log"));
			while(true){
				str = br.readLine();
				cnt++;
				if(str==null){
					break;
				}
				//39669, 1月份, 31210-3月份, 
				if(str.indexOf("50492")!=0 || str.indexOf(" 3=")<0){
					continue;
				}
				String sTime,cTime,price,qty,sqty;
				sTime = str.substring(str.indexOf(" 0=")+3,str.indexOf(" ",str.indexOf(" 0=")+3));
				cTime = str.substring(str.indexOf(" 3=")+3,str.indexOf(" ",str.indexOf(" 3=")+3));
				price = str.substring(str.indexOf(" 16=")+4,str.indexOf(" ",str.indexOf(" 16=")+4));
				qty = str.substring(str.indexOf(" 18=")+4,str.indexOf(" ",str.indexOf(" 18=")+4));
				sqty = str.substring(str.indexOf(" 19=")+4,str.indexOf(" ",str.indexOf(" 19=")+4));
				Start.put(createBean(sTime,cTime,price,qty,sqty));
			}
		}catch(Exception e){
			log.error("error:{}",e);
		}		
		log.trace("讀取結束");
	}
	private tickData createBean(String sTime,String cTime,String price,String qty,String sqty){
		tickData p=new tickData();
		p.setsTime(Integer.parseInt(sTime));//系統時間
		p.settTime(Integer.parseInt(cTime));//成交時間
		p.setPrice(Integer.parseInt(price));//成交價格
		p.setQty(Integer.parseInt(qty));//成交數量
		p.setSumqty(Integer.parseInt(sqty));//累積數量
//		log.trace("p:{}",p.toString());
		return p;
	}
}
